<?php
/**
 * Created by PhpStorm.
 * User: guokunsheng
 * Date: 2022/8/3
 * Time: 下午4:28
 */

namespace app\common\lib\astrolog;

use app\common\lib\horoscope\Horoscope;

/**
 * Class AuthenticatePlayboy
 * @package app\common\lib\astrolog
 */
class AuthenticatePlayboy extends LogicBase
{
    /**
     * 单例
     * @var AuthenticatePlayboy
     */
    protected static $instance;

    /**
     * 计算报告时产生的错误信息
     * @var string
     */
    protected $error = '';

    /**
     * 用户档案信息
     * @var array
     */
    protected $userRecord = [];

    /**
     * 匹配档案的星盘数据
     * @var array
     */
    protected $astroData = [];

    /**
     * 新逻辑的星盘数据
     * @var array
     */
    protected $newAstroData = [];

    /**
     * 八字数据
     * @var array
     */
    protected $horoscopeData = [];

    /**
     * 星盘配置
     * @var array
     */
    protected $setting = [
        'natal' => [
            'planet' => [
                [1, 7.5], [1, 6], [1, 3.5], [1, 4], [1, 4], [1, 4.5], [1, 4.5], [1, 2.5], [1, 2.5], [1, 2.5],
                [0, 0], [0, 0], [0, 0], [0, 0], [1, 2.5], [0, 0], [0, 0], [1, 2.5], [1, 2.5], [1, 2.5], [1, 2.5]
            ],
            'phase' => [
                0 => [1, 0], 60 => [1, 0], 90 => [1, 0], 120 => [1, 0], 180 => [1, 0],
                45 => [0, 0], 135 => [0, 0], 30 => [0, 0], 150 => [0, 0], 72 => [0, 0], 144 => [0, 0]
            ],
            'arabic' => [
                [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0],
                [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0],
                [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]
            ],
            'h_sys' => 'p',
            'firdaria' => 'default',
            'bound_type' => 'default',
            'ecliptic' => 0,
            'profection_push_direction' => 0,
            'decanates' => 0,
            'ayanamsa' => 0,
            'location_use' => 0
        ],
    ];

    /**
     * 新版逻辑的星盘配置
     * @var array[]
     */
    protected $setting2 = [
        'natal' => [
            'planet' => [
                [1, 1], [1, 1], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0],
                [0, 0], [0, 0], [0, 0], [0, 0], [1, 2.5], [0, 0], [0, 0], [1, 2.5], [1, 2.5], [1, 2.5], [1, 2.5]
            ],
            'phase' => [
                0 => [1, 8], 60 => [1, 6], 90 => [1, 7], 120 => [1, 7], 180 => [1, 7],
                45 => [0, 0], 135 => [0, 0], 30 => [0, 0], 150 => [0, 0], 72 => [0, 0], 144 => [0, 0]
            ],
            'arabic' => [
                [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0],
                [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0],
                [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]
            ],
            'h_sys' => 'p',
            'firdaria' => 'default',
            'bound_type' => 'default',
            'ecliptic' => 0,
            'profection_push_direction' => 0,
            'decanates' => 0,
            'ayanamsa' => 0,
            'location_use' => 0
        ],
    ];

    /**
     * 获取实例
     * @return AuthenticatePlayboy
     */
    public static function getInstance(): AuthenticatePlayboy
    {
        if (!(self::$instance instanceof self))
        {
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * 设置档案信息
     * @param array $record
     * @return AuthenticatePlayboy
     */
    public function setUserRecord($record = []): AuthenticatePlayboy
    {
        $this->userRecord = $record;
        return $this;
    }

    /**
     * 计算星盘数据
     * @return $this
     */
    private function getAstroData(): self
    {
        // 初始化当前星盘数据
        $this->astroData = [];
        // 档案本命星盘数据
        $data = Astrolog::getInstance()
            ->setRecode1($this->userRecord)
            ->setExecPrefix(config('astrolog.prefix'))
            // 设置为true获取星盘结构数据与互容接纳数据
            ->setIsAstrolabe(true)
            ->setUserSetting($this->setting)
            // version>1会计算行星中点相位、光线围攻、夹宫、夹星、夹制、夹辅
            ->setVersion(1)
            ->setGetDatas(['natal'])
            ->getAstroDatas()
            ->getDatas('natal');
        $this->astroData = json_decode(json_encode($data), true);
        $data2 = Astrolog::getInstance()
            ->setRecode1($this->userRecord)
            ->setExecPrefix(config('astrolog.prefix'))
            // 设置为true获取星盘结构数据与互容接纳数据
            ->setIsAstrolabe(true)
            ->setUserSetting($this->setting2)
            // version>1会计算行星中点相位、光线围攻、夹宫、夹星、夹制、夹辅
            ->setVersion(1)
            ->setGetDatas(['natal'])
            ->getAstroDatas()
            ->getDatas('natal');
        $this->newAstroData = json_decode(json_encode($data2), true);


        // 初始化八字数据，档案的八字信息
        $now = time();
        $advance = [
            'year' => date('Y', $now) * 1,
            'month' => date('m', $now) * 1,
            'day' => date('d', $now) * 1,
            'hour' => date('H', $now) * 1,
            'minute' => date('i', $now) * 1,
            'timezone' => 8,
            'is_summer' => 0,
        ];
        $this->horoscopeData = Horoscope::getInstance(['recode' => $this->userRecord, 'advance' => $advance])->getUserData();

        $this->horoscopeData['shishen'] = Horoscope::getInstance()->getShishen();

        return $this;
    }

    /**
     * 获取错误信息
     * 调用方式：$errorMessage = AuthenticatePlayboy::getInstance()->getError();
     * @return string
     */
    public function getError(): string
    {
        return $this->error;
    }

    /**
     * 鉴“渣”神器
     * 调用方式：AuthenticatePlayboy::getInstance()->setUserRecord($userRecord)->init();
     *  $userRecord array 具体的档案信息
     *  {
     *      "probability": 61, // 渣 可能性（概率）
     *      "code": [ // 依据 最低三条
     *          "10000000", // 依据 （影响星级在词条中携带`level`）
     *          "10000501", // 依据 （影响星级在词条中携带`level`）
     *          "100101", // 依据 （影响星级在词条中携带`level`）
     *          "100201", // 依据 （影响星级在词条中携带`level`）
     *          "10030100", // “不靠谱”的表现形式
     *          "10030101", // “不靠谱”的表现形式
     *          "10040800", // “不靠谱”的表现形式
     *          "10040801", // “不靠谱”的表现形式
     *          "100508" // 对异性的态度（总共有6种）
     *      ]
     *  }
     */
    public function init()
    {
        $res = $this->free(); // 获取免费计算的数据
        /**
         * “不靠谱”的表现形式
         * 根据金星落座和月亮落座，每个两条
         */
        $res['code'][] = '1003' . $this->modNumLength2($this->astroData['planets'][3]['in_sign_id'] - 1) . '00';
        $res['code'][] = '1003' . $this->modNumLength2($this->astroData['planets'][3]['in_sign_id'] - 1) . '01';
        $res['code'][] = '1004' . $this->modNumLength2($this->astroData['planets'][1]['in_sign_id'] - 1) . '00';
        $res['code'][] = '1004' . $this->modNumLength2($this->astroData['planets'][1]['in_sign_id'] - 1) . '01';
        /**
         * 对异性的态度手机上只显示6个词条
         * 逻辑：5宫主落座，一个词条匹配两个星座
         */
        $res['code'][] = '1005' . $this->modNumLength2($this->astroData['houses'][5]['protect_ancient_insign_id'] - 1);
        return $res;
    }

    /**
     * 免费计算部分
     * 调用方式：AuthenticatePlayboy::getInstance()->setUserRecord($userRecord)->free();
     *  $userRecord array 具体的档案信息
     *  {
     *      "probability": 61, // 渣 可能性（概率）
     *      "code": [ // 依据 最低三条
     *          "10000000",
     *          "10000501",
     *          "100101",
     *          "100201"
     *      ]
     *  }
     */
    public function free()
    {
        $res = [];
        $this->getAstroData();

        $score = 0;
        /**
         * 金星落座：
         * 金白羊 +5：
         * 金金牛 +2
         * 金双子 +4
         * 金巨蟹 +3
         * 金狮子 +2
         * 金处女 +4
         * 金天秤 +2
         * 金天蝎 +4
         * 金射手 +4
         * 金摩羯 +0
         * 金水瓶 +1
         * 金双鱼 +5
         */
        switch ($this->astroData['planets'][3]['in_sign_id'])
        {
            case 1:
                $score += 5;
                break;
            case 2:
                $score += 2;
                break;
            case 3:
                $score += 4;
                break;
            case 4:
                $score += 3;
                break;
            case 5:
                $score += 2;
                break;
            case 6:
                $score += 4;
                break;
            case 7:
                $score += 2;
                break;
            case 8:
                $score += 4;
                break;
            case 9:
                $score += 4;
                break;
            case 10:
                $score += 0;
                break;
            case 11:
                $score += 1;
                break;
            case 12:
                $score += 5;
                break;
        }
        /**
         * 金星落宫：
         * 金1 +3
         * 金2 +2
         * 金3 +2
         * 金4 +1
         * 金5 +4
         * 金6 +2
         * 金7 +3
         * 金8 +5
         * 金9 +2
         * 金10 +1
         * 金11 +4
         * 金12 +2
         */
        switch ($this->astroData['planets'][3]['in_house_id'])
        {
            case 1:
                $score += 3;
                break;
            case 2:
                $score += 2;
                break;
            case 3:
                $score += 2;
                break;
            case 4:
                $score += 1;
                break;
            case 5:
                $score += 4;
                break;
            case 6:
                $score += 2;
                break;
            case 7:
                $score += 3;
                break;
            case 8:
                $score += 5;
                break;
            case 9:
                $score += 2;
                break;
            case 10:
                $score += 1;
                break;
            case 11:
                $score += 4;
                break;
            case 12:
                $score += 2;
                break;
        }
        /**
         * 太阳落宫：
         * 日1  +0
         * 日2  +1
         * 日3  +1
         * 日4  +1
         * 日5  +2
         * 日6  +1
         * 日7  +1
         * 日8  +3
         * 日9  +1
         * 日10 +0
         * 日11 +1
         * 日12 +3
         */
        switch ($this->astroData['planets'][0]['in_house_id'])
        {
            case 1:
                $score += 0;
                break;
            case 2:
                $score += 1;
                break;
            case 3:
                $score += 1;
                break;
            case 4:
                $score += 1;
                break;
            case 5:
                $score += 2;
                break;
            case 6:
                $score += 1;
                break;
            case 7:
                $score += 1;
                break;
            case 8:
                $score += 3;
                break;
            case 9:
                $score += 1;
                break;
            case 10:
                $score += 0;
                break;
            case 11:
                $score += 1;
                break;
            case 12:
                $score += 3;
                break;
        }
        /**
         * 太阳落陷 在原基础上+2
         */
        if ($this->astroData['planets'][0]['ancient']['walls'] === 2
            || $this->astroData['planets'][0]['ancient']['promote'] === 2)
        {
            $score += 2;
        }
        /**
         * 月亮落宫：
         * 月1  +0
         * 月2  +1
         * 月3  +1
         * 月4  +0
         * 月5  +2
         * 月6  +1
         * 月7  +0
         * 月8  +3
         * 月9  +1
         * 月10 +0
         * 月11 +1
         * 月12 +3
         */
        switch ($this->astroData['planets'][1]['in_house_id'])
        {
            case 1:
                $score += 0;
                break;
            case 2:
                $score += 1;
                break;
            case 3:
                $score += 1;
                break;
            case 4:
                $score += 0;
                break;
            case 5:
                $score += 2;
                break;
            case 6:
                $score += 1;
                break;
            case 7:
                $score += 0;
                break;
            case 8:
                $score += 3;
                break;
            case 9:
                $score += 1;
                break;
            case 10:
                $score += 0;
                break;
            case 11:
                $score += 1;
                break;
            case 12:
                $score += 3;
                break;
        }
        /**
         * 月亮落陷 在原基础上+2
         */
        if ($this->astroData['planets'][1]['ancient']['walls'] === 2
            || $this->astroData['planets'][1]['ancient']['promote'] === 2)
        {
            $score += 2;
        }
        /**
         * 命主落宫：
         * 命主1  +0
         * 命主2  +1
         * 命主3  +1
         * 命主4  +0
         * 命主5  +2
         * 命主6  +1
         * 命主7  +1
         * 命主8  +3
         * 命主9  +1
         * 命主10 +0
         * 命主11 +1
         * 命主12 +3
         */
        switch ($this->astroData['planets'][$this->astroData['houses'][1]['protect_ancient_id']]['in_house_id'])
        {
            case 1:
                $score += 0;
                break;
            case 2:
                $score += 1;
                break;
            case 3:
                $score += 1;
                break;
            case 4:
                $score += 0;
                break;
            case 5:
                $score += 2;
                break;
            case 6:
                $score += 1;
                break;
            case 7:
                $score += 1;
                break;
            case 8:
                $score += 3;
                break;
            case 9:
                $score += 1;
                break;
            case 10:
                $score += 0;
                break;
            case 11:
                $score += 1;
                break;
            case 12:
                $score += 3;
                break;
        }
        /**
         * 命主是8宫主 +1
         */
        if ($this->astroData['houses'][1]['protect_ancient_id'] === $this->astroData['houses'][8]['protect_ancient_id'])
        {
            $score += 1;
        }
        /**
         * 命主是12宫主 +1
         */
        if ($this->astroData['houses'][1]['protect_ancient_id'] === $this->astroData['houses'][12]['protect_ancient_id'])
        {
            $score += 1;
        }
        /**
         * 命主落陷 在原基础上+2
         */
        if ($this->astroData['planets'][$this->astroData['houses'][1]['protect_ancient_id']]['ancient']['walls'] === 2
            || $this->astroData['planets'][$this->astroData['houses'][1]['protect_ancient_id']]['ancient']['promote'] === 2)
        {
            $score += 2;
        }
        /**
         * 7宫主落宫：
         * 落1 +3
         * 落2 +2
         * 落3 +2
         * 落4 +1
         * 落5 +4
         * 落6 +2
         * 落7 +3
         * 落8 +5
         * 落9 +2
         * 落10 +1
         * 落11 +4
         * 落12 +2
         */
        switch ($this->astroData['planets'][$this->astroData['houses'][7]['protect_ancient_id']]['in_house_id'])
        {
            case 1:
                $score += 3;
                break;
            case 2:
                $score += 2;
                break;
            case 3:
                $score += 2;
                break;
            case 4:
                $score += 1;
                break;
            case 5:
                $score += 4;
                break;
            case 6:
                $score += 2;
                break;
            case 7:
                $score += 3;
                break;
            case 8:
                $score += 5;
                break;
            case 9:
                $score += 2;
                break;
            case 10:
                $score += 1;
                break;
            case 11:
                $score += 4;
                break;
            case 12:
                $score += 2;
                break;
        }
        /**
         * 7宫主落陷 +2
         */
        if ($this->astroData['planets'][$this->astroData['houses'][7]['protect_ancient_id']]['ancient']['walls'] === 2
            || $this->astroData['planets'][$this->astroData['houses'][7]['protect_ancient_id']]['ancient']['promote'] === 2)
        {
            $score += 2;
        }
        /**
         * 7宫内星：
         * 火不落陷 +1  落陷+3
         * 木不落陷 +3  落陷+5
         * 土不落陷 +0  落陷+1
         * 水不落陷 +1  落陷+2
         * 天 +3
         * 海 +3
         * 冥 +1
         */
        if ($this->astroData['houses'][7]['have_planet_num'] >= 1)
        {
            foreach ($this->astroData['houses'][7]['in_house_area_planet_info'] as $k1 => $v1)
            {
                if ($this->astroData['planets'][$v1['id']]['ancient']['walls'] === 2
                    || $this->astroData['planets'][$v1['id']]['ancient']['promote'] === 2)
                {
                    switch ($v1['id'])
                    {
                        case 2:
                            $score += 2;
                            break;
                        case 4:
                            $score += 3;
                            break;
                        case 5:
                            $score += 5;
                            break;
                        case 6:
                            $score += 1;
                            break;
                        case 7:
                            $score += 3;
                            break;
                        case 8:
                            $score += 3;
                            break;
                        case 9:
                            $score += 1;
                            break;
                    }
                } else
                {
                    switch ($v1['id'])
                    {
                        case 2:
                            $score += 1;
                            break;
                        case 4:
                            $score += 1;
                            break;
                        case 5:
                            $score += 3;
                            break;
                        case 6:
                            $score += 0;
                            break;
                        case 7:
                            $score += 3;
                            break;
                        case 8:
                            $score += 3;
                            break;
                        case 9:
                            $score += 1;
                            break;
                    }
                }

            }
        }
        /**
         * 1宫内星：
         * 火不落陷 +1  落陷+3
         * 木不落陷 +3  落陷+5
         * 土不落陷 +1  落陷+3
         * 水不落陷 +1  落陷+2
         * 天 +3
         * 海 +3
         * 冥 +3
         * 8宫主 +3
         * 12宫主 +3
         */
        if ($this->astroData['houses'][1]['have_planet_num'] >= 1)
        {
            foreach ($this->astroData['houses'][1]['in_house_area_planet_info'] as $k2 => $v2)
            {
                if ($this->astroData['planets'][$v2['id']]['ancient']['walls'] === 2
                    || $this->astroData['planets'][$v2['id']]['ancient']['promote'] === 2)
                {
                    switch ($v2['id'])
                    {
                        case 2:
                            $score += 2;
                            break;
                        case 4:
                            $score += 3;
                            break;
                        case 5:
                            $score += 5;
                            break;
                        case 6:
                            $score += 3;
                            break;
                        case 7:
                            $score += 3;
                            break;
                        case 8:
                            $score += 3;
                            break;
                        case 9:
                            $score += 3;
                            break;
                    }
                } else
                {
                    switch ($v2['id'])
                    {
                        case 2:
                            $score += 1;
                            break;
                        case 4:
                            $score += 1;
                            break;
                        case 5:
                            $score += 3;
                            break;
                        case 6:
                            $score += 1;
                            break;
                        case 7:
                            $score += 3;
                            break;
                        case 8:
                            $score += 3;
                            break;
                        case 9:
                            $score += 3;
                            break;
                    }
                }
                if ($v2['id'] === $this->astroData['houses'][8]['protect_ancient_id'])
                {
                    $score += 3;
                }
                if ($v2['id'] === $this->astroData['houses'][12]['protect_ancient_id'])
                {
                    $score += 3;
                }
            }
        }
        /**
         * 5宫内星：
         * 火不落陷 +1  落陷+3
         * 木不落陷 +3  落陷+5
         * 土不落陷 +1  落陷+3
         * 水不落陷 +1  落陷+2
         * 天 +3
         * 海 +3
         * 冥 +3
         */
        if ($this->astroData['houses'][5]['have_planet_num'] >= 1)
        {
            foreach ($this->astroData['houses'][5]['in_house_area_planet_info'] as $k3 => $v3)
            {
                if ($this->astroData['planets'][$v3['id']]['ancient']['walls'] === 2
                    || $this->astroData['planets'][$v3['id']]['ancient']['promote'] === 2)
                {
                    switch ($v3['id'])
                    {
                        case 2:
                            $score += 2;
                            break;
                        case 4:
                            $score += 3;
                            break;
                        case 5:
                            $score += 5;
                            break;
                        case 6:
                            $score += 3;
                            break;
                        case 7:
                            $score += 3;
                            break;
                        case 8:
                            $score += 3;
                            break;
                        case 9:
                            $score += 3;
                            break;
                    }
                } else
                {
                    switch ($v3['id'])
                    {
                        case 2:
                            $score += 1;
                            break;
                        case 4:
                            $score += 1;
                            break;
                        case 5:
                            $score += 3;
                            break;
                        case 6:
                            $score += 1;
                            break;
                        case 7:
                            $score += 3;
                            break;
                        case 8:
                            $score += 3;
                            break;
                        case 9:
                            $score += 3;
                            break;
                    }
                }
            }
        }
        /**
         * 11宫内星：
         * 木不落陷+2 落陷+4
         * 日不落陷+1 落陷+3
         * 5宫主不落陷 +3 落陷+4
         * 7宫主不落陷 +3 落陷+4
         */
        if ($this->astroData['houses'][11]['have_planet_num'] >= 1)
        {
            foreach ($this->astroData['houses'][11]['in_house_area_planet_info'] as $k4 => $v4)
            {
                if ($this->astroData['planets'][$v4['id']]['ancient']['walls'] === 2
                    || $this->astroData['planets'][$v4['id']]['ancient']['promote'] === 2)
                {
                    if ($v4['id'] === $this->astroData['houses'][5]['protect_ancient_id']
                        || $v4['id'] === $this->astroData['houses'][7]['protect_ancient_id'])
                    {
                        $score += 4;
                    } else
                    {
                        switch ($v4['id'])
                        {
                            case 0:
                                $score += 3;
                                break;
                            case 5:
                                $score += 4;
                                break;
                        }
                    }
                } else
                {
                    if ($v4['id'] === $this->astroData['houses'][5]['protect_ancient_id']
                        || $v4['id'] === $this->astroData['houses'][7]['protect_ancient_id'])
                    {
                        $score += 3;
                    } else
                    {
                        switch ($v4['id'])
                        {
                            case 0:
                                $score += 1;
                                break;
                            case 5:
                                $score += 2;
                                break;
                        }
                    }
                }
            }
        }
        /**
         * 11宫主星：
         * 落1 +2
         * 落5 +3
         * 落7 +4
         */
        switch ($this->astroData['houses'][11]['protect_ancient_inhouse_id'])
        {
            case 1:
                $score += 2;
                break;
            case 5:
                $score += 3;
                break;
            case 7:
                $score += 4;
                break;
        }
        /**
         * 相位：
         * 命主（合、接纳、互溶、刑、冲）8主 +5
         */
        if ($this->isHouseProtectPhaseHouseProtect($this->astroData, 1, 8, [0, 90, 180])
            || $this->isHouseProtectReceptOrMutualReceptHouseProtect($this->astroData, 1, 8))
        {
            $score += 5;
        }
        /**
         * 命主（合、接纳、互溶、刑、冲）12主 +5
         */
        if ($this->isHouseProtectPhaseHouseProtect($this->astroData, 1, 12, [0, 90, 180])
            || $this->isHouseProtectReceptOrMutualReceptHouseProtect($this->astroData, 1, 12))
        {
            $score += 5;
        }
        /**
         * 命主（合、接纳、互溶）11宫主 +3
         */
        if ($this->isHouseProtectPhaseHouseProtect($this->astroData, 1, 11, [0])
            || $this->isHouseProtectReceptOrMutualReceptHouseProtect($this->astroData, 1, 11))
        {
            $score += 3;
        }
        /**
         * 金星（合、接纳、互溶）11宫主 +4
         */
        if ($this->isHouseProtectPhasePlanet($this->astroData, 11, 3, [0])
            || $this->isHouseProtectReceptOrMutualReceptPlanet($this->astroData, 11, 3))
        {
            $score += 4;
        }
        /**
         * 7宫主（合、接纳、互溶）11宫主 +4
         */
        if ($this->isHouseProtectPhaseHouseProtect($this->astroData, 1, 11, [0])
            || $this->isHouseProtectReceptOrMutualReceptHouseProtect($this->astroData, 1, 11))
        {
            $score += 3;
        }
        /**
         * 太阳（合、接纳、互溶、刑、冲）8主 +3
         */
        if ($this->isHouseProtectPhasePlanet($this->astroData, 8, 0, [0, 90, 180])
            || $this->isHouseProtectReceptOrMutualReceptPlanet($this->astroData, 8, 0))
        {
            $score += 3;
        }
        /**
         * 太阳（合、接纳、互溶、刑、冲）12主 +3
         */
        if ($this->isHouseProtectPhasePlanet($this->astroData, 12, 0, [0, 90, 180])
            || $this->isHouseProtectReceptOrMutualReceptPlanet($this->astroData, 12, 0))
        {
            $score += 3;
        }
        /**
         * 7宫主（合、接纳、互溶、刑、冲）8主 +2
         */
        if ($this->isHouseProtectPhaseHouseProtect($this->astroData, 7, 8, [0, 90, 180])
            || $this->isHouseProtectReceptOrMutualReceptHouseProtect($this->astroData, 7, 8))
        {
            $score += 2;
        }
        /**
         * 7宫主（合、接纳、互溶、刑、冲）12主 +2
         */
        if ($this->isHouseProtectPhaseHouseProtect($this->astroData, 7, 12, [0, 90, 180])
            || $this->isHouseProtectReceptOrMutualReceptHouseProtect($this->astroData, 7, 12))
        {
            $score += 2;
        }
        /**
         * 7宫主与天、海、冥有相位 +2
         */
        if ($this->isHouseProtectPhasePlanet($this->astroData, 7, 7, [0, 60, 90, 120, 180])
            || $this->isHouseProtectPhasePlanet($this->astroData, 7, 8, [0, 60, 90, 120, 180])
            || $this->isHouseProtectPhasePlanet($this->astroData, 7, 9, [0, 60, 90, 120, 180]))
        {
            $score += 2;
        }
        /**
         * 太阳落（巨蟹、双鱼、天蝎）+2
         */
        if ($this->isPlanetInSign($this->astroData['planets'], 0, [4, 8, 12]))
        {
            $score += 2;
        } /**
         * 太阳落（白羊、射手、双子）+2
         */
        elseif ($this->isPlanetInSign($this->astroData['planets'], 0, [1, 3, 9]))
        {
            $score += 2;
        }
        /**
         * 命主落（巨蟹、双鱼、天蝎）+2
         */
        if ($this->isHouseProtectInSign($this->astroData, 1, [4, 8, 12]))
        {
            $score += 2;
        } /**
         * 命主落（白羊、射手、双子）+2
         */
        elseif ($this->isHouseProtectInSign($this->astroData, 1, [1, 3, 9]))
        {
            $score += 2;
        }
        /**
         * 日冥（合、刑、冲） +2
         */
        if ($this->isPlanetPhasePlanet($this->astroData['planets'], 0, 9, [0, 90, 180]))
        {
            $score += 2;
        }
        /**
         * 日海（合、刑、冲） +2
         */
        if ($this->isPlanetPhasePlanet($this->astroData['planets'], 0, 8, [0, 90, 180]))
        {
            $score += 2;
        }
        /**
         * 日天（合、刑、冲） +2
         */
        if ($this->isPlanetPhasePlanet($this->astroData['planets'], 0, 7, [0, 90, 180]))
        {
            $score += 2;
        }
        /**
         * 金月困难相位 +4
         */
        if ($this->isPlanetPhasePlanet($this->astroData['planets'], 1, 3, [90, 180]))
        {
            $score += 4;
        }
        /**
         * 金火有相位 +2
         */
        if ($this->isPlanetPhasePlanet($this->astroData['planets'], 3, 4, [0, 60, 90, 120, 180]))
        {
            $score += 2;
        }
        /**
         * 金土困难相位 +2
         */
        if ($this->isPlanetPhasePlanet($this->astroData['planets'], 3, 6, [90, 180]))
        {
            $score += 2;
        }
        /**
         * 金木有相位（互溶、接纳也算） +2
         */
        if ($this->isPlanetPhasePlanet($this->astroData['planets'], 3, 5, [0, 60, 90, 120, 180])
            || $this->isPlanetReceptOrMutualReceptPlanet($this->astroData['characteristic'], 3, 5))
        {
            $score += 2;
        }
        /**
         * 金海（合、刑、冲）+5
         */
        if ($this->isPlanetPhasePlanet($this->astroData['planets'], 3, 8, [0, 90, 180]))
        {
            $score += 5;
        }
        /**
         * 金冥（合、刑、冲）+3
         */
        if ($this->isPlanetPhasePlanet($this->astroData['planets'], 3, 9, [0, 90, 180]))
        {
            $score += 3;
        }
        /**
         * 金天（合、刑、冲）+5
         */
        if ($this->isPlanetPhasePlanet($this->astroData['planets'], 3, 7, [0, 90, 180]))
        {
            $score += 5;
        }
        /**
         * 火冥（合、刑、冲）+5
         */
        if ($this->isPlanetPhasePlanet($this->astroData['planets'], 4, 9, [0, 90, 180]))
        {
            $score += 5;
        }
        /**
         * 火海（合、刑、冲）+5
         */
        if ($this->isPlanetPhasePlanet($this->astroData['planets'], 4, 8, [0, 90, 180]))
        {
            $score += 5;
        }
        /**
         * 火月（合、刑、冲）+5
         */
        if ($this->isPlanetPhasePlanet($this->astroData['planets'], 4, 1, [0, 90, 180]))
        {
            $score += 5;
        }
        /**
         * 结果向上取整
         * 0-10%    0-18分
         * 11%-30%  19-28分
         * 31%-50%  29-38分
         * 51%-70%  39-48分
         * 71%-90%  49-59分
         * 91%以上  60分以上
         */
        if ($score >= 60)
        {
            // 78-60= 28 / 40 * 10 = 10 + 91 = 98%
            $res['probability'] = ceil(($score - 60) / 40 * 10 + 91);
            if ($res['probability'] > 99)
            {
                $res['probability'] = 99;
            }
        } elseif ($score >= 49)
        {
            // 54-39= 5 / 10 * 20 = 10 + 71 = 81%
            $res['probability'] = ceil(($score - 49) / 10 * 20 + 71);
            if ($res['probability'] > 90)
            {
                $res['probability'] = 90;
            }
        } elseif ($score >= 39)
        {
            // 44-39= 5 / 10 * 20 = 10 + 51 = 61%
            $res['probability'] = ceil(($score - 39) / 10 * 20 + 51);
            if ($res['probability'] > 70)
            {
                $res['probability'] = 70;
            }
        } elseif ($score >= 29)
        {
            // 34-29= 5 / 10 * 20 = 10 + 31 = 41%
            $res['probability'] = ceil(($score - 29) / 10 * 20 + 31);
            if ($res['probability'] > 50)
            {
                $res['probability'] = 50;
            }
        } elseif ($score >= 19)
        {
            // 23-19= 4 / 10 * 20 = 8 + 11 = 19%
            $res['probability'] = ceil(($score - 19) / 10 * 20 + 11);
            if ($res['probability'] > 30)
            {
                $res['probability'] = 30;
            }
        } else
        {
            // 9 / 18 * 10 = 5%
            $res['probability'] = ceil($score / 18) * 10;
            if ($res['probability'] > 10)
            {
                $res['probability'] = 10;
            } elseif ($score < 1)
            {
                $res['probability'] = 1;
            }
        }
        /**
         * "渣"的依据
         * 1.金星和9颗行星相位，每个相位分两种情况（两种情况为——好相位：合/三合/六合；不好相位：刑克/对冲）
         * 2.金星落12宫位
         * 3.金星落12星座
         * 4.金星空相，就写金星空相的特性
         */
        foreach ([0, 1, 2, 4, 5, 6, 7, 8, 9] as $v)
        {
            if ($this->isPlanetPhasePlanet($this->astroData['planets'], 3, $v, [0, 60, 120]))
            {
                $res['code'][] = '10000' . $v . '00';
            } elseif ($this->isPlanetPhasePlanet($this->astroData['planets'], 3, $v, [90, 180]))
            {
                $res['code'][] = '10000' . $v . '01';
            }
        }
        /**
         * 金星空相
         */
//        if ($this->isPlanetEmptyPhase($this->astroData['planets'], 3))
        if (empty($res['code']))
        {
            $res['code'][] = $res['code'][] = '10000302';
        }
        /**
         * 金星落宫
         */
        $res['code'][] = '1001' . $this->modNumLength2($this->astroData['planets'][3]['in_house_id'] - 1);
        /**
         * 金星落座
         */
        $res['code'][] = '1002' . $this->modNumLength2($this->astroData['planets'][3]['in_sign_id'] - 1);

        // 占星渣力值
        $p5Power = $this->calcPowerScore(5);
        $p8Power = $this->calcPowerScore(8);
        // 迷乱值=木海势值相加
        //	计算金星的势
        //		定位
        //			日 月10，金9，水5，火8，木土2，天海冥0.5
        //		宫位
        //			合轴
        //				升10，顶9，降7，底5
        //			落宫（如不合轴才算）
        //				1、5、7+5，4、9、10、11+3
        //		相位
        //			类型系数
        //				合刑冲1，拱0.8，半拱0.7
        //			容许系数
        //				1度内1
        //				1-3度0.9
        //				3-5度0.85
        //				5度外0.8
        //			日月+15，水+5，火+12，命主+10
        //		以上相加，不封顶
        $p3Power = $this->calcPowerScore(3);
        //	计算5/7宫活跃
        //		有无月金木火海落5/7宫
        //			有则t=1
        //			无则t=0.7
        //		情欲值=金星势*t*0.03
        //	占星渣力值=迷乱值*情欲值
        if ($this->isPlanetInHouse($this->newAstroData['planets'], 1, [5, 7])
            || $this->isPlanetInHouse($this->newAstroData['planets'], 3, [5, 7])
            || $this->isPlanetInHouse($this->newAstroData['planets'], 4, [5, 7])
            || $this->isPlanetInHouse($this->newAstroData['planets'], 5, [5, 7])
            || $this->isPlanetInHouse($this->newAstroData['planets'], 8, [5, 7]))
        {
            $t = 1;
        } else
        {
            $t = 0.7;
        }

        $res['astro_score'] = ($p5Power + $p8Power) * ($p3Power * $t * 0.03);

        $res['bazi_score'] = $this->calcBaziScore();

        return $res;
    }

    /**
     * 计算木海金  势值
     * @param $p
     * @return float|int
     */
    private function calcPowerScore($p)
    {
        $score = 0;
        //	计算木星、海王的势
        //		定位
        //			日 月10，金9，水5，火8，木土2，天海冥0.5
        //		宫位
        //			合轴
        //				升10，顶9，降7，底5
        //			落宫（如不合轴才算）
        //				1、5、7+5，4、9、10、11+3
        //			顶星（距离天顶最近）
        //				+6
        //		相位
        //			类型系数
        //				合刑冲1，拱0.8，半拱0.7
        //			容许系数
        //				1度内1
        //				1-3度0.9
        //				3-5度0.85
        //				5度外0.8
        //			日月金+15，水+5，火+12，命主+10
        //		以上相加，取峰值40，大于40取40，木星最后所得结果需/2
        //		迷乱值=木海势值相加
        $proSigns = [
            5 => 9,
            8 => 12,
            3 => [2, 7]
        ];
        if ($this->isPlanetInSign($this->newAstroData['planets'], 0, $proSigns[$p]))
        {
            $score += 10;
        }
        if ($this->isPlanetInSign($this->newAstroData['planets'], 1, $proSigns[$p]))
        {
            $score += 10;
        }
        if ($this->isPlanetInSign($this->newAstroData['planets'], 3, $proSigns[$p]))
        {
            $score += 9;
        }
        if ($this->isPlanetInSign($this->newAstroData['planets'], 2, $proSigns[$p]))
        {
            $score += 5;
        }
        if ($this->isPlanetInSign($this->newAstroData['planets'], 4, $proSigns[$p]))
        {
            $score += 8;
        }
        if ($this->isPlanetInSign($this->newAstroData['planets'], 5, $proSigns[$p]))
        {
            $score += 2;
        }
        if ($this->isPlanetInSign($this->newAstroData['planets'], 6, $proSigns[$p]))
        {
            $score += 2;
        }
        if ($this->isPlanetInSign($this->newAstroData['planets'], 7, $proSigns[$p]))
        {
            $score += 0.5;
        }
        if ($this->isPlanetInSign($this->newAstroData['planets'], 8, $proSigns[$p]))
        {
            $score += 0.5;
        }
        if ($this->isPlanetInSign($this->newAstroData['planets'], 9, $proSigns[$p]))
        {
            $score += 0.5;
        }
        // 合轴
        if ($this->isPlanetPhasePlanet($this->newAstroData['planets'], $p, ASC, [0]))
        {
            $score += 10;
        } elseif ($this->isPlanetPhasePlanet($this->newAstroData['planets'], $p, IC, [0]))
        {
            $score += 5;
        } elseif ($this->isPlanetPhasePlanet($this->newAstroData['planets'], $p, DES, [0]))
        {
            $score += 7;
        } elseif ($this->isPlanetPhasePlanet($this->newAstroData['planets'], $p, MC, [0]))
        {
            $score += 9;
        } else
        {
            // 1、5、7+5，4、9、10、11+3
            if ($this->isPlanetInHouse($this->newAstroData['planets'], $p, [1, 5, 7]))
            {
                $score += 5;
            } elseif ($this->isPlanetInHouse($this->newAstroData['planets'], $p, [4, 9, 10, 11]))
            {
                $score += 3;
            }
        }
        if ($p !== 3)
        {
            // 顶星（距离天顶最近）+6
            $mcDeg = $this->newAstroData['planets'][$p]['deg'];
            $nearestMc1 = abs($this->newAstroData['planets'][$p]['deg'] - $mcDeg);
            $nearestMc2 = 360 - abs($this->newAstroData['planets'][$p]['deg'] - $mcDeg);
            $nearestMc = $nearestMc1 < $nearestMc2 ? $nearestMc1 : $nearestMc2;
            $isNearest = true;
            for ($i = 0; $i < 10; $i++)
            {
                if ($isNearest === true && (abs($this->newAstroData['planets'][$p]['deg'] - $mcDeg) < $nearestMc
                        || 360 - abs($this->newAstroData['planets'][$p]['deg'] - $mcDeg) < $nearestMc))
                {
                    $isNearest = false;
                }
            }
            if ($isNearest)
            {
                $score += 6;
            }
        }
        // 相位
        // 	类型系数
        // 		合刑冲1，拱0.8，半拱0.7
        // 	容许系数
        // 		1度内1
        // 		1-3度0.9
        // 		3-5度0.85
        // 		5度外0.8
        // 	日月金+15，水+5，火+12，命主+6
        if (!empty($this->newAstroData['planets'][$p]['phase']))
        {
            foreach ($this->newAstroData['planets'][$p]['phase'] as $k => $v)
            {
                if (in_array($v['phase_e'], [0, 90, 180], true))
                {
                    $t1 = 1;
                } elseif ($v['phase_e'] === 120)
                {
                    $t1 = 0.8;
                } else
                {
                    $t1 = 0.7;
                }
                if ($v['phase_orb'] <= 1)
                {
                    $t2 = 1;
                } elseif ($v['phase_orb'] <= 3)
                {
                    $t2 = 0.9;
                } elseif ($v['phase_orb'] <= 5)
                {
                    $t2 = 0.85;
                } else
                {
                    $t2 = 0.8;
                }
                if (in_array($v['id'], [0, 1, 3], true))
                {
                    $score += 15 * $t1 * $t2;
                }
                if ($v['id'] === 2)
                {
                    $score += 5 * $t1 * $t2;
                }
                if ($v['id'] === 4)
                {
                    $score += 12 * $t1 * $t2;
                }
                if ($v['id'] === $this->newAstroData['houses'][1]['protect_ancient_id'])
                {
                    $score += 6 * $t1 * $t2;
                }
            }
        }
        //	以上相加，取峰值40，大于40取40，木星最后所得结果需/2
        if ($p !== 3)
        {
            if ($score > 40)
            {
                $score = 40;
            }
            if ($p === 5)
            {
                $score /= 2;
            }
        }

        return $score;
    }

    private function calcBaziScore()
    {
        $score = 0;
        // 八字渣力值
        //	五行旺度
        //		位置系数
        //			月支1，日支0.8，年支时支0.5
        //		阴阳系数
        //			阴干（包括藏干）0.7，阳干1
        //		本藏系数
        //			本气1，藏气0.3
        //		透干系数（如该地支藏干透到天干上）
        //			月干1.5，日干1.5，时干1.4，年干1.3，否则为1
        //			多次透干，以透干值最高分数*1.2（多透一次则乘1次）
        //		找出地支中所有藏干，如某干存在于多个地支，则 位置*阴阳*本藏 多次相加得到地气值，地气值*透干系数=该干实象值
        //		未在地支出现的天干，看八字天干是否出现，如果有，每出现一次+（0.5*阴阳系数）的虚象值，如果没有则为零
        //		计算每个五行旺度，如该五行（阴阳两干）仅有虚象值，其旺度=阴阳两干虚象相加/2，如该五行有实象值，则其旺度=实象+虚象*1.5
        $bazi = $this->horoscopeData['bazi'];// 八字下标为1～8 奇数为天干  偶数为地支
        $canggan = $this->horoscopeData['canggan'];// 藏干下标为 0~3 对应年、月、日、时
        /**
         * 天干属性表
         *  yy：阴阳系数 阳1   阴0.75
         *  wx: 五行属性 0=>木,1=>火,2=>土,3=>金,4=>水
         *  sx: 实象值
         *  xx：虚像值
         */
        $tianganList = [
            '甲' => ['yy' => 1, 'wx' => 0, 'sx' => 0, 'xx' => 0], '乙' => ['yy' => 0.7, 'wx' => 0, 'sx' => 0, 'xx' => 0],
            '丙' => ['yy' => 1, 'wx' => 1, 'sx' => 0, 'xx' => 0], '丁' => ['yy' => 0.7, 'wx' => 1, 'sx' => 0, 'xx' => 0],
            '戊' => ['yy' => 1, 'wx' => 2, 'sx' => 0, 'xx' => 0], '己' => ['yy' => 0.7, 'wx' => 2, 'sx' => 0, 'xx' => 0],
            '庚' => ['yy' => 1, 'wx' => 3, 'sx' => 0, 'xx' => 0], '辛' => ['yy' => 0.7, 'wx' => 3, 'sx' => 0, 'xx' => 0],
            '壬' => ['yy' => 1, 'wx' => 4, 'sx' => 0, 'xx' => 0], '癸' => ['yy' => 0.7, 'wx' => 4, 'sx' => 0, 'xx' => 0]
        ];
        // 找出所有的地支藏干 （地支藏干数组 合并后去重）
        $dizhiCangganList = array_unique(array_merge($canggan[0], $canggan[1], $canggan[2], $canggan[3]));
        // 未在地支中出现的天干
        $tianganNotInDizhi = array_diff(['甲', '乙', '丙', '丁', '戊', '己', '庚', '辛', '壬', '癸'], $dizhiCangganList);
        // 虚象值计算
        if (!empty($tianganNotInDizhi))
        {
            foreach ($tianganNotInDizhi as $tg)
            {
                if ($tg === $bazi[1])
                {
                    // 每出现一次+（0.5*阴阳系数）
                    $tianganList[$tg]['xx'] += 0.5 * $tianganList[$tg]['yy'];
                }
            }
        }
        // 实象值计算
        foreach ($dizhiCangganList as $cg)
        {
            $diqiScore = 0;
            // 年柱 位置系数：0.5
            if (in_array($cg, $canggan[0], true))
            {
                // 本藏系数 本气1，藏气0.3
                $bc = $cg === $canggan[0][0] ? 1 : 0.3;
                // 位置*阴阳*本藏
                $diqiScore += 0.5 * $tianganList[$cg]['yy'] * $bc;
            }
            // 月柱 位置系数：1
            if (in_array($cg, $canggan[1], true))
            {
                // 本藏系数 本气1，藏气0.3
                $bc = $cg === $canggan[1][0] ? 1 : 0.3;
                // 位置*阴阳*本藏
                $diqiScore += $tianganList[$cg]['yy'] * $bc;
            }
            // 日柱 位置系数：0.8
            if (in_array($cg, $canggan[2], true))
            {
                // 本藏系数 本气1，藏气0.3
                $bc = $cg === $canggan[2][0] ? 1 : 0.3;
                // 位置*阴阳*本藏
                $diqiScore += 0.8 * $tianganList[$cg]['yy'] * $bc;
            }
            // 时柱 位置系数：0.5
            if (in_array($cg, $canggan[3], true))
            {
                // 本藏系数 本气1，藏气0.3
                $bc = $cg === $canggan[3][0] ? 1 : 0.3;
                // 位置*阴阳*本藏
                $diqiScore += 0.5 * $tianganList[$cg]['yy'] * $bc;
            }
            //		透干系数（如该地支藏干透到天干上）
            //			月干1.5，日干1.5，时干1.4，年干1.3
            //			多次透干，以透干值最高分数*1.2（多透一次则乘1次）
            $tg = 1;
            $tgNum = 0;

            if ($cg === $bazi[3])
            {
                $tg = $tg < 1.5 ? 1.5 : $tg;
                $tgNum++;
            }
            if ($cg === $bazi[5])
            {
                $tg = $tg < 1.5 ? 1.5 : $tg;
                $tgNum++;
            }
            if ($cg === $bazi[7])
            {
                $tg = $tg < 1.4 ? 1.4 : $tg;
                $tgNum++;
            }
            if ($cg === $bazi[1])
            {
                $tg = $tg < 1.3 ? 1.3 : $tg;
                $tgNum++;
            }
            // 地气值*透干系数=该干实象值
            $tianganList[$cg]['sx'] = $diqiScore * $tg * (1.2 ** $tgNum);
        }
        // 五行旺度计算 0=>木,1=>火,2=>土,3=>金,4=>水
        $wxw = [0, 0, 0, 0, 0];
        if ($tianganList['甲']['sx'] > 0 || $tianganList['乙']['sx'] > 0)
        {
            $x = 1.5;
        } else
        {
            $x = 0.5;
        }
        $wxw[0] = $tianganList['甲']['sx'] + $tianganList['乙']['sx'] + ($tianganList['甲']['xx'] + $tianganList['乙']['xx']) * $x;
        if ($tianganList['丙']['sx'] > 0 || $tianganList['丁']['sx'] > 0)
        {
            $x = 1.5;
        } else
        {
            $x = 0.5;
        }
        $wxw[1] = $tianganList['丙']['sx'] + $tianganList['丁']['sx'] + ($tianganList['丙']['xx'] + $tianganList['丁']['xx']) * $x;
        if ($tianganList['戊']['sx'] > 0 || $tianganList['己']['sx'] > 0)
        {
            $x = 1.5;
        } else
        {
            $x = 0.5;
        }
        $wxw[2] = $tianganList['戊']['sx'] + $tianganList['己']['sx'] + ($tianganList['戊']['xx'] + $tianganList['己']['xx']) * $x;
        if ($tianganList['庚']['sx'] > 0 || $tianganList['辛']['sx'] > 0)
        {
            $x = 1.5;
        } else
        {
            $x = 0.5;
        }
        $wxw[3] = $tianganList['庚']['sx'] + $tianganList['辛']['sx'] + ($tianganList['庚']['xx'] + $tianganList['辛']['xx']) * $x;
        if ($tianganList['壬']['sx'] > 0 || $tianganList['癸']['sx'] > 0)
        {
            $x = 1.5;
        } else
        {
            $x = 0.5;
        }
        $wxw[4] = $tianganList['壬']['sx'] + $tianganList['癸']['sx'] + ($tianganList['壬']['xx'] + $tianganList['癸']['xx']) * $x;

        /**
         * 库藏
         * 检测地支是否是辰戌丑未
         *  不是   只看本气
         *  是     除本气考量第四个元素（库藏），辰-癸，戌-丁，丑-辛，未-乙
         */
        //	男命
        //		十神（只取一项）
        //			月干、时干、日支本气（或库藏）同时有偏财和食神+10，此时有正财透干或为某支某气再+6
        //			月干、时干、日支本气（或库藏）同时有正财和偏财+8，此时有食神透干或为某支本气再+6
        //			正财偏财食神之一透干，同时地支有另两个的本气+9
        //			八字中同时有正财偏财食神本气+8
        //			天干同时有正偏财或地支同时有正偏财本气+6
        //			天干地支本气有偏财和食神+5
        //			八字有偏财或食神（地支记本气），+4
        $needKucang = in_array($bazi[6], ['辰', '戌', '丑', '未'], true);
        /**
         * 正财 => 财
         * 偏财 => 才
         * 正印 => 印
         * 偏印 => 枭
         * 食神 => 食
         * 伤官 => 伤
         * 比肩 => 比
         * 劫财 => 劫
         * 七杀 => 杀
         * 正官 => 官
         */
        $condShishen = [
            $this->horoscopeData['shishen1'][1],
            $this->horoscopeData['shishen1'][3],
            $this->horoscopeData['shishen2'][2][0]
        ];
        if ($needKucang)
        {
            $kucang = ['辰' => '癸', '戌' => '丁', '丑' => '辛', '未' => '乙'];
            $condShishen[] = $kucang[$bazi[6]];
        }
        $benqiShishen = [
            $this->horoscopeData['shishen2'][0][0],
            $this->horoscopeData['shishen2'][1][0],
            $this->horoscopeData['shishen2'][2][0],
            $this->horoscopeData['shishen2'][3][0],
        ];
        $tgList = [$bazi[1], $bazi[3], $bazi[4], $bazi[7]];
        $dizhiList = [$bazi[2], $bazi[4], $bazi[6], $bazi[8]];
        $tianganBenqiShishen = array_unique(array_merge($this->horoscopeData['shishen1'], $benqiShishen));
        $shishenScore = 0;
        // 女命 正财换正官，偏财换七杀
        if ($this->userRecord['type'] === 1)
        {
            $zc = '财';
            $pc = '才';
        } else
        {
            $zc = '官';
            $pc = '杀';
        }

        // 月干、时干、日支本气（或库藏）同时有偏财和食神+10，此时有正财透干或为某支某气再+6
        if (in_array($pc, $condShishen, true)
            && in_array('食', $condShishen, true))
        {
            $shishenScore += 6;
        }
        // 月干、时干、日支本气（或库藏）同时有正财和偏财+8，此时有食神透干或为某支本气再+6
        if ($shishenScore === 0 && in_array($zc, $condShishen, true)
            && in_array($pc, $condShishen, true))
        {
            $shishenScore += 6;
        }
        // 正财偏财食神之一透干，同时地支有另两个的本气+9
        if ($shishenScore === 0)
        {
            // 地支本气
            $benqiList = [$canggan[0][0], $canggan[1][0], $canggan[2][0], $canggan[3][0]];
            $cdShishen = [$zc, $pc, '食'];
            if ((in_array($this->horoscopeData['shishen1'][0], $cdShishen, true)
                    && in_array($bazi[1], $dizhiCangganList, true)
                    && in_array($bazi[3], $benqiList, true)
                    && in_array($bazi[7], $benqiList, true))
                || (in_array($this->horoscopeData['shishen1'][1], $cdShishen, true)
                    && in_array($bazi[3], $dizhiCangganList, true)
                    && in_array($bazi[1], $benqiList, true)
                    && in_array($bazi[7], $benqiList, true))
                || (in_array($this->horoscopeData['shishen1'][3], $cdShishen, true)
                    && in_array($bazi[7], $dizhiCangganList, true)
                    && in_array($bazi[1], $benqiList, true)
                    && in_array($bazi[3], $benqiList, true)))
            {
                $shishenScore += 9;
            }
        } // 八字中同时有正财偏财食神本气+8
        if ($shishenScore === 0 && in_array($zc, $benqiShishen, true)
            && in_array($pc, $benqiShishen, true)
            && in_array('食', $benqiShishen, true))
        {
            $shishenScore += 8;
        } // 天干同时有正偏财或地支同时有正偏财本气+6
        if ($shishenScore === 0 && ((in_array($zc, $this->horoscopeData['shishen1'], true)
                    && in_array($pc, $this->horoscopeData['shishen1'], true))
                || (in_array($zc, $benqiShishen, true)
                    && in_array($pc, $benqiShishen, true))))
        {
            $shishenScore += 6;
        } // 天干地支本气有偏财和食神+5
        if ($shishenScore === 0 && in_array($pc, $tianganBenqiShishen, true)
            && in_array('食', $tianganBenqiShishen, true))
        {
            $shishenScore += 5;
        } // 八字有偏财或食神（地支记本气），+4
        if ($shishenScore === 0 && (in_array($pc, $tianganBenqiShishen, true)
                || in_array('食', $tianganBenqiShishen, true)))
        {
            $shishenScore += 4;
        }
        //		五行
        //			看是否有木克土
        //				天干同时出现木土
        //				某柱出现 甲辰、乙丑、甲戌、乙未
        //				地支出现 卯辰、卯午、寅亥、寅丑
        $isMuKeTu = false;
        if ((in_array('甲', $tgList, true) || in_array('乙', $tgList, true))
            && (in_array('戊', $tgList, true) || in_array('己', $tgList, true)))
        {
            $isMuKeTu = true;
        }
        $yz = $bazi[1] . $bazi[2];
        $mz = $bazi[3] . $bazi[4];
        $dz = $bazi[5] . $bazi[6];
        $hz = $bazi[7] . $bazi[8];
        $cdZhu = ['甲辰', '乙丑', '甲戌', '乙未'];
        if ($isMuKeTu === false
            && (in_array($yz, $cdZhu, true)
                || in_array($mz, $cdZhu, true)
                || in_array($dz, $cdZhu, true)
                || in_array($hz, $cdZhu, true)))
        {
            $isMuKeTu = true;
        }
        if ($isMuKeTu === false
            && ((in_array('卯', $dizhiList, true) && (in_array('辰', $dizhiList, true) || in_array('午', $dizhiList, true)))
                || (in_array('寅', $dizhiList, true) && (in_array('亥', $dizhiList, true) || in_array('丑', $dizhiList, true)))))
        {
            $isMuKeTu = true;
        }
        //			计算水的旺度
        //				水旺最终值=水旺-土旺+木旺*0.7-金旺*0.7+火旺*0.2（有木克土时不减土旺）
        $swScore = $wxw[4] + $wxw[0] * 0.7 - $wxw[3] * 0.7 + $wxw[1] * 0.2;
        if (!$isMuKeTu)
        {
            $swScore -= $wxw[2];
        }
        //		计算
        //			如有木克土且十神取值不为零，八字渣力值=水旺最终值*十神值/5*30
        //			如有木克土但十神取值为零，八字渣力值=水旺最终值*25
        //			如无木克土但十神取值不为零，八字渣力值=水旺最终值*25
        //				系数可能需要下调
        //			如无木克土且十神取值为零，八字渣力值=水旺最终值*20
        //	女命
        //		同男命，正财换正官，偏财换七杀
        if ($isMuKeTu && $shishenScore > 0)
        {
            $score = $swScore * $shishenScore / 5 * 30;
        } elseif ($isMuKeTu && $shishenScore === 0)
        {
            $score = $swScore * 25;
        } elseif (!$isMuKeTu && $shishenScore > 0)
        {
            $score = $swScore * 25;
        } else
        {
            $score = $swScore * 20;
        }

        return $score;
    }
}
